﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace 花店管理系统.geren
{
    public partial class Pinglun : Form
    {
        private const int STAR_SIZE = 50;
        private PictureBox[] stars;
        private TextBox commentTextBox;
        private int selectedRating = 0;
        private string commentImageFilePath;
        // 图片路径变量
        private string imagePath = "";
        public DataRow CommentForOrder { get; set; }
        public Pinglun()
        {
            InitializeComponent();
            InitializeStars();

            if (CommentForOrder != null)
            {
                textBox1.Text = CommentForOrder["O_name"].ToString(); // 预填充评论文本框
                                                                      // 根据需要预填充其他控件
            }
        }


        //打分
        private void InitializeStars()
        {
            stars = new PictureBox[5];
            for (int i = 0; i < 5; i++)
            {
                PictureBox star = new PictureBox
                {
                    Image = Image.FromFile("D:\\大二下\\数据库编程\\花店管理系统\\花店管理系统\\bin\\Debug\\按键图标\\评分星2.jpg"),
                    Location = new Point(i * STAR_SIZE, 0),
                    Size = new Size(STAR_SIZE, STAR_SIZE),
                    Tag = i
                };
                star.SizeMode = PictureBoxSizeMode.Zoom; // 设置PictureBox的SizeMode为Zoom
                star.MouseEnter += Star_MouseEnter;
                star.MouseLeave += Star_MouseLeave;
                star.Click += Star_Click;
                panel1.Controls.Add(star);
                stars[i] = star;
            }
        }

        private void Star_MouseEnter(object sender, EventArgs e)
        {
            PictureBox star = (PictureBox)sender;
            int index = (int)star.Tag;
            for (int i = 0; i <= index; i++)
            {
                stars[i].Image = Image.FromFile("D:\\大二下\\数据库编程\\花店管理系统\\花店管理系统\\bin\\Debug\\按键图标\\评分星1.jpg");
            }
        }

        private void Star_MouseLeave(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                if (i >= selectedRating)
                {
                    stars[i].Image = Image.FromFile("D:\\大二下\\数据库编程\\花店管理系统\\花店管理系统\\bin\\Debug\\按键图标\\评分星2.jpg");
                }
                else
                {
                    stars[i].Image = Image.FromFile("D:\\大二下\\数据库编程\\花店管理系统\\花店管理系统\\bin\\Debug\\按键图标\\评分星1.jpg");
                }
            }
        }

        private void Star_Click(object sender, EventArgs e)
        {
            PictureBox star = (PictureBox)sender;
            int rating = (int)star.Tag + 1;
            selectedRating = rating;
            CommentForOrder["O_dafen"] = rating;
        }

        private void btnCanle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //评论
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox1.Text))
            {
                CommentForOrder["O_pinglun"] = textBox1.Text;
                UpdateDB();
                MessageBox.Show("评论成功！");
                this.Close();
            }
            else
            {
                MessageBox.Show("请输入评论内容");
            }
        }

        void UpdateDB() // 更新数据源
        {
            try
            {
                SqlDataAdapter daOrder = new SqlDataAdapter("SELECT * FROM Torder", DB.cn);
                SqlCommandBuilder dbOrder = new SqlCommandBuilder(daOrder);
                daOrder.Update((DataTable)CommentForOrder.Table);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        private void btnShangchuang_Click(object sender, EventArgs e)
        {

           
        }

       

        private void Pinglun_Load(object sender, EventArgs e)
        {
            
            
        }
    }
    
}
